
// pages/operation/operation_work_detail/operation_work_detail.js
const innerAudioContext = wx.createInnerAudioContext()
const urls = require('../../../utils/url.js').urls;
const http = require('../../../utils/url.js').http
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    num: 5,//后端给的分数,显示相应的星星
    one_1: '',
    two_1: '',

    fh:'',
    zj:'',
    sj:'',
    zt:'',
    xq:'',
    gdrq:'',
    jjyy:'',
    gzyy:'',
    wcrq:'',
    tx: '../../../image/mrtx.png',
     nc:'',
     pj:'',

    showView1:false,
    showView2:false,
    ypdz:'',
    bl: false,
    time: 0,

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    showView1: (options.showView == "true" ? true : false)
    showView2: (options.showView == "true" ? true : false)


    wx.showNavigationBarLoading();
    var that = this;
  
    var param = {
      id: wx.getStorageSync('ywgdid')
    };
    http(urls.ordersDetails, param, function (res) {
      console.log(res.data)
      wx.hideNavigationBarLoading();
      that.setData({
       
        fh: res.data.room,
        zj: res.data.zjh,
        sj: res.data.phone,
        zt: res.data.zt,
        xq: res.data.describe,
        gdrq: res.data.create_time,
        jjyy: res.data.refuse_reason,
        gzyy: res.data.cause,
        wcrq: res.data.complete_time,
        num: parseInt(res.data.xj),
        nc: res.data.pjr,
        pj: res.data.ms,
        nm: res.data.isnm,
        ypdz: res.data.voice_path,
        time: res.data.yyms

      })


      //  先判断工单在什么状态
      if (wx.getStorageSync('ywgdzt') == 2) {
        // 已完成
        if (that.data.nm == 1) {
          // 不是匿名
        that.setData({
          showView2: true,
        })
        }
      }
      else {
        that.setData({
          showView2: false,
        })
      }


      //:展示后台给的评分
      that.setData({
        one_1: that.data.num,
        two_1: 5 - that.data.num
      })
      // 判断音频地址是否存在
      if (that.data.yydz == '') {
        that.setData({
          showView1: false
        })
      } else {
        that.setData({
          showView1: true
        })
      }
    })

    var params = {
      openid: app.globalData.openid
    };
    http(urls.details, params, function (res) {
      // console.log(res.data)
      if (that.data.nm == 1) {
        that.setData({
          tx: res.data.avatarurl,

        })
      }

    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  //播放声音
  play: function () {

    if (this.data.bl == false) {
      this.setData({
        bl: true
      })
    } else {
      this.setData({
        bl: false
      })
    }

    innerAudioContext.onError((res) => {　　　　　　 // 播放音频失败的回调
    })
    innerAudioContext.src = urls.base + 'uploed/' + this.data.ypdz; // 这里可以是录音的临时路径
    if (this.data.bl == true) {
      innerAudioContext.play();
    } else {
      innerAudioContext.stop();
      innerAudioContext.pause();
    }
    innerAudioContext.onEnded(() => {
      this.setData({
        bl: false
      })
    })
    innerAudioContext.onError(() => {
      this.setData({
        bl: false
      })
    })
  },
})